package com.onecm.biz.merchant.controller;
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.controller;</#if> 

import java.util.Set;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.frame.common.base.bean.AjaxResultCustom;
import com.frame.common.base.bean.AjaxResultObject;
import com.frame.common.ds.bean.PageDTO;
import com.frame.common.ds.bean.TableDataInfoCustom;
import com.frame.common.ds.util.QueryHelpMybatisPlus;
import com.frame.common.log.annotation.Log;
import com.frame.common.log.enums.LogBusinessType;
import com.frame.common.base.bean.AjaxResultObject;
import com.frame.common.ds.bean.PageDTO;
import com.frame.common.ds.bean.TableDataInfoObject;
import com.frame.common.ds.util.QueryHelpMybatisPlus;
import com.frame.common.log.annotation.Log;
import com.frame.common.log.enums.LogBusinessType;
import com.frame.common.security.annotation.FrameRequiresPermission;
import java.util.Arrays;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.entity.${classInfo.className};
import com.service.${classInfo.className}Service;
import com.dto.${classInfo.className}DTO;

/**
 * @description ${classInfo.classComment}
 * @author ${authorName}
 * @date ${.now?string('yyyy-MM-dd')}
 */
@AllArgsConstructor
@RestController
@RequestMapping("/${classInfo.className?uncap_first}")
public class ${classInfo.className}Controller {
  private static ${classInfo.className}Converter converter = ${classInfo.className}Converter.INSTANCE;

    private final ${classInfo.className}Service service;

    @GetMapping("")
    @SuppressWarnings({"rawtypes", "unchecked"})
    public TableDataInfoCustom<${classInfo.className}Bean> list(PageDTO<${classInfo.className}> page, ${classInfo.className}QueryDTO query) {
    PageDTO<${classInfo.className}> pageDto = service.page(page, QueryHelpMybatisPlus.handleWrapper(query));
    return new TableDataInfoCustom(pageDto.convert(e-> converter.toBean(e)).getRecords());
    }

    @GetMapping(value = "/{id}")
    public AjaxResultCustom<${classInfo.className}Bean> getInfo(//
    		@PathVariable Long id,//
    		 ${classInfo.className}QueryDTO query//
    		) {
    ${classInfo.className} entity = null;
    if (id >= 0) {
      entity = service.getById(id);
    } else {
      entity = service.getOne(QueryHelpMybatisPlus.handleWrapper(query));
    }
    return AjaxResultCustom.success(converter.toBean(entity));
    }

    @Log(title = "添加-${classInfo.classComment}", businessType = LogBusinessType.INSERT)
    @PostMapping
    public AjaxResultObject add(@Validated @RequestBody ${classInfo.className}AddDTO dto) {
//        if (service.count(
//            Wrappers.<${classInfo.className}>lambdaQuery()
//                .eq(${classInfo.className}::, entity.())
//        ) > 0) {
//            return AjaxResultObject.error("新增数据失败，数据已存在");
//        }
    ${classInfo.className} entity = converter.toEntity(dto);
        return AjaxResultObject.success(service.save(entity));
    }

    @Log(title = "修改-${classInfo.classComment}", businessType = LogBusinessType.UPDATE)
    @PutMapping(value = "/{id}")
    public AjaxResultObject edit(@Validated @RequestBody ${classInfo.className}EditDTO dto) {
//        if (service.count(
//            Wrappers.<${classInfo.className}>lambdaQuery()
//                .ne(${classInfo.className}::getId, entity.getId())
//                .eq(${classInfo.className}::, entity.())
//        ) > 0) {
//            return AjaxResultObject.error("修改数据失败，数据已存在");
//        }
    ${classInfo.className} entity = converter.toEntity(dto);
    return AjaxResultObject.success(service.updateById(entity));
    }
 
  @Log(title = "删除-${classInfo.classComment}", businessType = LogBusinessType.DELETE)
  @DeleteMapping
  public AjaxResultObject remove(Set<Long> ids) {
    return AjaxResultObject.success(service.removeByIds(ids));
  }

  @Log(title = "删除-${classInfo.classComment}", businessType = LogBusinessType.DELETE)
  @DeleteMapping("/{id}")
  public AjaxResultObject remove(@PathVariable Long id) {
    return AjaxResultObject.success(service.removeById(id));
  }
}
